-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: Construct Timestamp with tz correctly near DST border #21407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello @mroeschke! Thanks for updating the PR. Cheers ! There are no PEP8 issues in this Pull Request. 🍻 Comment last updated on June 13, 2018 at 03:17 Hours UTC |
Codecov Report
@@ Coverage Diff @@
## master #21407 +/- ##
=======================================
Coverage 91.89% 91.89%
=======================================
Files 153 153
Lines 49600 49600
=======================================
Hits 45580 45580
Misses 4020 4020
Continue to review full report at Codecov.
|
pandas/_libs/tslibs/conversion.pyx
Outdated
if ts.tzinfo is not None: | ||
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'): | ||
# tz.localize does not correctly localize Timestamps near DST | ||
# but correctly localizes datetimes | ||
if hasattr(ts, 'to_pydatetime'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Elsewhere we've used not PyDatetimeCheckExact(ts)
as a standin for isinstance(ts, pd.Timestamp)
. This might also be use case for the nanos
kwarg.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jbrockmendel. Seems clearer than trying to get Timestamp
to quack
pandas/_libs/tslibs/conversion.pyx
Outdated
if ts.tzinfo is not None: | ||
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'): | ||
# tz.localize does not correctly localize Timestamps near DST | ||
# but correctly localizes datetimes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC tz.localize
(or possibly tz.normalize
if thats relevant) operates by calling ts
methods. Is this potentially something we can fix "higher up" in Timestamp
?
pandas/_libs/tslibs/conversion.pyx
Outdated
@@ -347,10 +347,9 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz, | |||
if tz is not None: | |||
tz = maybe_get_tz(tz) | |||
|
|||
# sort of a temporary hack | |||
if ts.tzinfo is not None: | |||
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check might be superfluous since datetimes
natively have the astimezone
method. Then this whole block might be able to be simplified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, you can try that and see if it works. maybe add a comment anyhow
doc/source/whatsnew/v0.23.1.txt
Outdated
@@ -129,6 +129,10 @@ Bug Fixes | |||
- Bug in :func:`concat` where error was raised in concatenating :class:`Series` with numpy scalar and tuple names (:issue:`21015`) | |||
- Bug in :func:`concat` warning message providing the wrong guidance for future behavior (:issue:`21101`) | |||
|
|||
**Timezones** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to 0.23.2
pandas/tests/frame/test_operators.py
Outdated
@@ -992,6 +992,16 @@ def test_boolean_comparison(self): | |||
result = df == tup | |||
assert_frame_equal(result, expected) | |||
|
|||
@pytest.mark.parametrize('tz', [None, 'America/New_York']) | |||
def test_boolean_compare_transpose_tzindex_with_dst(self, tz): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you move to test_timezones
pandas/_libs/tslibs/conversion.pyx
Outdated
@@ -347,10 +347,9 @@ cdef _TSObject convert_datetime_to_tsobject(datetime ts, object tz, | |||
if tz is not None: | |||
tz = maybe_get_tz(tz) | |||
|
|||
# sort of a temporary hack | |||
if ts.tzinfo is not None: | |||
if hasattr(tz, 'normalize') and hasattr(ts.tzinfo, '_utcoffset'): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, you can try that and see if it works. maybe add a comment anyhow
thanks @mroeschke nice clean up! can you review any outstanding issues that involve dst. this may go a long way towards solving them (if so, then pls PR for tests). |
(cherry picked from commit bc4ccd7)
(cherry picked from commit bc4ccd7)
closes #19970
closes #20854
git diff upstream/master -u -- "*.py" | flake8 --diff
So I think the reason we need to convert a
Timestamp
todatetime
branch is because of howTimestamp
behave withnormalize
explained by this #18618 (comment)